#!/usr/bin/env sh
#
# Copyright 2010 TimeZlicer
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

if [ $# -lt 1 ]; then
    echo $0 "<path to appcfg.py> [application root]"
    exit
fi

if [ $# == 2 ]; then
    for i in PythonFunction; do
        echo .......$i
        "$1"appcfg.py upload_data \
        --config_file=bulkloader.yaml --filename=$i.csv --kind=$i \
        --batch_size=100 --rps_limit=200 \
        $2
    done
else
    unset http_proxy
    unset https_proxy
    for i in PythonFunction; do
        echo .......$i
        echo 0 | PYTHONPATH='../web-dev:'$PYTHONPATH "$1"appcfg.py upload_data \
        --email=0 --passin --application=`grep application app.yaml | cut -d\  -f2` \
        --config_file=bulkloader.yaml --filename=$i.csv --kind=$i \
        --batch_size=100 --rps_limit=200 \
        --url=http://localhost:8080/_ah/remote_api
    done
fi

rm -fv bulkloader-log* bulkloader-progress*
